package com.caseeye.base
import org.springframework.util.ReflectionUtils

import scala.Tuple2
import com.caseeye.util.ClassUtils._
import java.lang.reflect.Field

trait Reflectable {

    def <<(t : Tuple2[String, AnyRef]) : Reflectable = {
        if (t == null || t == None) return this

        val clazz = this.getClass
        val fieldName = t._1
        val fieldValue = t._2
        val field = ReflectionUtils.findField(clazz, fieldName)
        ReflectionUtils.makeAccessible(field)
        ReflectionUtils.setField(field, this, fieldValue)
        this
    }
}